<template>
  <div class="goods-detail">
    <nav-bar class="goods-detail-title">
      <div slot="left" class="goods-detail-back" @click="backClick">
        <img src="~assets/img/common/back.svg" alt>
      </div>
      <ul slot="center" class="title">
        <li
          v-for="(item, index) in title"
          :key="index"
          :class="{active:currentIndex==index}"
          @click="titleClick(index)"
        >{{item}}</li>
      </ul>
    </nav-bar>
  </div>
</template>

<script>
import NavBar from "components/common/navbar/NavBar";

export default {
  data() {
    return {
      title: ["商品", "参数", "评论", "推荐"],
      currentIndex: 0
    };
  },
  methods: {
    titleClick(index) {
      this.currentIndex = index;
    },
    backClick() {
      // this.$router.back() 都行
      this.$router.go(-1);
    }
  },
  components: {
    NavBar
  },
  computed: {},
  watch: {},
  //生命周期 - 创建完成（可以访问当前this实例）
  created() {},
  //生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  updated() {}, //生命周期 - 更新之后
  activated() {} //如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang='less' scoped>
//@import url(); 引入公共css类
.goods-detail {
  height: 45px;
  .goods-detail-back {
    font-size: 0;
    img {
      padding-top: 2px;
    }
  }

  .goods-detail-title {
    background: #fff;
    border-bottom: 1px solid #ccc;
    .title {
      display: flex;
      flex-flow: row nowrap;
      li {
        &:not(:last-child) {
          padding-right: 30px;
        }
      }
    }
  }
}
.active {
  color: #ff5777;
}
</style>